﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class Users
    {
        public bool insert(Model.Users mLKMT)
        {
            string sql= "insert into Users (UserID,Name,Number) values(@UserID, @Name,@Number)";
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@UserID", mLKMT.UserID ));
            sqlParams.Add(new SqlParameter("@Name", mLKMT.Name ));
            sqlParams.Add(new SqlParameter("@Number", mLKMT.Number ));
            return DBUtitlity.DbHelperSQL.ExecuteSql(sql, sqlParams);
        }
        public bool update(Model.Users  mLKMT, string oldUserID)
        {
            string sql = "update Users set UserID=@UserID, Name= @Name,Number=@Number where UserID=@oldUserID";
            List<SqlParameter> sqlParams=new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@UserID", mLKMT.UserID ));
            sqlParams.Add(new SqlParameter("@Name", mLKMT.Name ));
            sqlParams.Add(new SqlParameter("@Number", mLKMT.Number ));
            sqlParams.Add(new SqlParameter("@oldUserID", oldUserID)); 
            return DBUtitlity.DbHelperSQL.ExecuteSql(sql, sqlParams);
        }
        public bool delete(string UserID)
        {
            string sql = "delete from Users where UserID=@UserID";
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@UserID", UserID));
            return DBUtitlity.DbHelperSQL.ExecuteSql(sql, sqlParams);
        }
        public DataTable select(string strWhere)
        {
            string sql = "select Users. UserID as UserID,Name,Number from Users ";
            //string sql = "select * from Users";
            if (strWhere != "")
            {
                sql +=" where " + strWhere;
            }
            return DBUtitlity.DbHelperSQL.Query(sql);
        }
    }
}
